import {createApp, setGlobalData} from '@miniu/data';
import {getSkinSettings} from './service/index';
App(
  createApp({
    defaultGlobalData: {
      count: 50,
      themeStyle: '', // 定义全局变量themeStyle
    },
    async onLaunch(options) {
      const res = await getSkinSettings(); // 模拟从后端获取颜色值
      this.setThemeStyle(res.data); // 改变色值
    },
    setThemeStyle({
      primaryColor = '#4caf50',
      bgColor = '#f1f1f1',
      titleColor = '#000000',
      textColor = '#333333',
      bannerImages = 'https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/70967f6ec4ac40bb9b17a673849e9fc6~tplv-k3u1fbpfcp-watermark.image?',
    }) {
      setGlobalData((globalData) => {
        globalData.themeStyle = `
        --primary-color: ${primaryColor};
        --bg-color: ${bgColor};
        --title-color: ${titleColor};
        --text-color: ${textColor};
        --banner-images: url('${bannerImages}');`;
      });
      // 设置页面背景色
      my.setBackgroundColor({
        backgroundColor: bgColor,
      });
    },
  })
);
